#include "motor_controller.h"

#include "Arduino.h"

MotorController::MotorController(int fpin, int bpin)
{
    forward_pin  = fpin;
    backward_pin = bpin;
}

void MotorController::init()
{
    pinMode(forward_pin, OUTPUT);
    pinMode(backward_pin, OUTPUT);
}

void MotorController::setSpeed(float speed,int flag)
{
    if(flag==1){
        digitalWrite(forward_pin,HIGH);
        digitalWrite(backward_pin,LOW);
        analogWrite(forward_pin, speed);
        analogWrite(backward_pin, 0);
    }
    else if(flag==-1){
        digitalWrite(forward_pin,LOW);
        digitalWrite(backward_pin,HIGH);
        analogWrite(forward_pin, 0);
        analogWrite(backward_pin, speed);
    }
    else if(flag==0){
        digitalWrite(forward_pin,LOW);
        digitalWrite(backward_pin,LOW);
        analogWrite(forward_pin, 0);
        analogWrite(backward_pin, 0);
    }
}